package com.lanou.lenanapp.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lanou.lenanapp.R;
import com.lanou.lenanapp.entity.greendao.LoginEntity;

import java.util.List;


/**
 * 登录提示信息列表适配器
 */
public class PopupWindowAdapter extends RecyclerView.Adapter<PopupWindowAdapter.PopuWindowViewHolder>{

    private List<LoginEntity> list;


    public void addData(List<LoginEntity> datas){
        this.list = datas;
        notifyDataSetChanged();
    }

    //自定义回调接口
    public interface onItemClickListener{
        void onItemOnClick(LoginEntity entity);
    }

    private onItemClickListener listener;
    public void setonItemClick (onItemClickListener l){
        this.listener = l;
    }


    class PopuWindowViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView popupTv;
        private int position;

        public PopuWindowViewHolder(View itemView) {
            super(itemView);
            popupTv = (TextView) itemView.findViewById(R.id.popupTv);
            popupTv.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if(list != null && list.size() > 0){
                LoginEntity l = list.get(position);
                if (listener != null){
                    listener.onItemOnClick(l);
                }
            }
        }
    }

    @Override
    public PopuWindowViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View v = inflater.inflate(R.layout.activity_popupwindow_gut, null);
        return new PopuWindowViewHolder(v);
    }

    @Override
    public void onBindViewHolder(PopuWindowViewHolder holder, int position) {
        if (list != null && list.size() > 0){
            LoginEntity l = list.get(position);
            holder.popupTv.setText(l.getPhone());
        }
        holder.position = position;
    }

    @Override
    public int getItemCount() {
        return list != null && list.size() > 0 ? list.size() : 0;
    }



}
